package model;

import java.util.List;

import base.BaseModel;
import base.BaseObserver;
import base.ResultCallBack;
import bean.BooksBean;
import bean.ResultBean;
import jiyun.com.yiyanmeng.http.HttpManager;
import jiyun.com.yiyanmeng.http.MySerivce;
import utils.RxUtil;

/**
 * Created by 裘翔 on 2019/11/6.
 */

public class BooksModel extends BaseModel {
    public void loadData(final ResultCallBack<List<BooksBean>> callBack) {
        MySerivce mySerivce = HttpManager.getInstance().getSerivce();
        mySerivce.getBook()
                .compose(RxUtil.<ResultBean<List<BooksBean>>>changeThread())
                .compose(RxUtil.<List<BooksBean>>changeResult())
                .subscribe(new BaseObserver<List<BooksBean>>() {
                    @Override
                    public void onSuccess(List<BooksBean> booksBeans) {
                        callBack.onSuccess(booksBeans);
                    }

                    @Override
                    public void onFail(String error) {
                        callBack.onFail(error);
                    }
                });
    }
}
